package cn.com.xuhx.testMapper;

import cn.com.xuhx.mapper.UserMapper;
import cn.com.xuhx.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Date;

/**
 * 插入测试
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class InsertTest {

    @Autowired
    private UserMapper userMapper;

    /**
     * 新增
     * 注意：
     *  使用BaseMapper新增，必须设置数据的ID为bigInt类型，映射java为Long类型，因为BaseMapper默认是使用雪花算法来为数据生成ID，并且可以返回ID
     */
    @Test
    public void testInsert(){
        //INSERT INTO T_USERS ( id, name, age, address, tel, sfzh, bornday ) VALUES ( ?, ?, ?, ?, ?, ?, ? )
        User user = new User("风晴雪", 15, "幽都", "18122233567", "320611535247762238", new Date());
        int result = userMapper.insert(user);
        System.out.println("变动数：" + result);
        System.out.println("新增数据ID：" + user.getId());
    }
}
